//
//  MONumberOfPersonnelOfWaitViewCell.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/8/9.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MONumberOfPersonnelOfWaitViewCell.h"

@interface MONumberOfPersonnelOfWaitViewCell ()

@property(nonatomic,strong)TYAttributedLabel *nameLabel;

@property(nonatomic,strong)UILabel *dateLabel;

@property(nonatomic,strong)UILabel  *businessNameLabel;


@end

@implementation MONumberOfPersonnelOfWaitViewCell

+(instancetype)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath
{
    //NSString *ID = [NSString stringWithFormat:@"Cell%ld%ld",(long)[indexPath section],(long)[indexPath row]];
    NSString *ID = @"MONumberOfPersonnelOfWaitViewCell";
    MONumberOfPersonnelOfWaitViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil){
        cell = [[MONumberOfPersonnelOfWaitViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell creatView];
    }
    return cell;
}


-(void)creatView
{
    [self addSubview:self.nameLabel];
    
    [self addSubview:self.businessNameLabel];
    
    [self addSubview:self.dateLabel];;
}

-(void)setModel:(MONumberOfPersonnelOfWaitModel *)model
{
    UIColor *sunBackCol0r;
    UIColor *contentColor;
    if ([model.readStatus integerValue]==1) {
        self.nameLabel.textColor = KBlackColor_919395;
        sunBackCol0r = KBlackColor_919395;
        contentColor = KBlackColor_919395;
    }else{
        self.nameLabel.textColor = KBlackColor_222222;
        //通知 收文 发文 任务 测评 公示
        if ([model.typeStr isEqualToString:@"任务"]) {
            sunBackCol0r = KYellowColor_E71020;
        }else if ([model.typeStr isEqualToString:@"测评"]){
            sunBackCol0r = KBlueColor_2C94FF;
        }else if ([model.typeStr isEqualToString:@"公示"]){
            sunBackCol0r = KGreenColor_B7DAFF;
        }else{
            sunBackCol0r = KRedColor_FF4040;
        }
        contentColor = KBlackColor_222222;
    }
    self.nameLabel.textContainer = [NSString stringWithContentStr:[NSString stringWithFormat:@"%@%@",@"   ",model.nameStr] contentColor:contentColor contentFont:16 rangeStr:model.typeStr rangBackgroundColor:sunBackCol0r rangeFont:9 rangeCorner:2 rangeRectCorner:UIRectCornerBottomLeft | UIRectCornerBottomRight | UIRectCornerTopLeft | UIRectCornerTopRight withViewWidth:SCREEN_WIDTH-28];
    [self.nameLabel sizeToFit];
    
    CGSize size = [NSString labelAutoCalculateRectWith:[NSString stringWithFormat:@"%@  %@%@",model.nameStr,model.typeStr,@"   "] WithFont:FONT_SIZE(16) MaxSize:CGSizeMake(SCREEN_WIDTH - 28, MAXFLOAT)];
    CGFloat height = size.height;
    if (height>20) {
        height +=15;
    }
    self.nameLabel.height = height;
    
    self.dateLabel.text = model.dateSr;
    
    self.businessNameLabel.text = [NSString stringWithFormat:@"业务名称：%@",[NSString passNullForString:model.businessNameStr]];
    
    self.businessNameLabel.y = self.nameLabel.bottom +34;
    self.dateLabel.y = self.businessNameLabel.y;
    
}


+ (CGFloat)heightForMONumberOfPersonnelOfWaitViewCellAndModel:(MONumberOfPersonnelOfWaitModel *)model
{
    CGSize size = [NSString labelAutoCalculateRectWith:[NSString stringWithFormat:@"%@  %@%@",model.nameStr,model.typeStr,@"   "] WithFont:FONT_SIZE(16) MaxSize:CGSizeMake(SCREEN_WIDTH - 28, MAXFLOAT)];
    CGFloat height = size.height;
    if (height>20) {
        height +=15;
    }
    
    height += 13;
    
    height += 34;
    
    height += 17*2;
    
    return height;
}


#pragma mark --
-(TYAttributedLabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [[TYAttributedLabel alloc]initWithFrame:CGRectMake(14, 20, SCREEN_WIDTH - 28, 1)];
        _nameLabel.font = FONT_SIZE(16);
        _nameLabel.textColor = KBlackColor_222222;
        _nameLabel.numberOfLines = 0;
    }
    return _nameLabel;
}

-(UILabel *)businessNameLabel
{
    if (!_businessNameLabel) {
        _businessNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, _nameLabel.bottom + 34, SCREEN_WIDTH - 28, 13)];
        _businessNameLabel.font = FONT_SIZE(12);
        _businessNameLabel.textColor = KBlueColor_2C94FF;
    }
    return _businessNameLabel;
}

-(UILabel *)dateLabel
{
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 26 - 120, _nameLabel.bottom + 34, 120, 13)];
        _dateLabel.font = FONT_SIZE(12);
        _dateLabel.textColor = KGrayColor_919395;
        _dateLabel.textAlignment = NSTextAlignmentRight;
    }
    return _dateLabel;
}


@end
